<?php
class keu_penerimaan_sijaka_model extends MY_Model {
	var $model = 'penerimaan_sijaka';
	
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	A.ID_SIJAKA, A.ID_ANGGOTA, A.TGL_PERMOHONAN, A.JANGKA_WAKTU, A.JML_DANA, A.NOMINAL_SPLIT, A.SUKU_BUNGA, 
							A.JENIS_RO, A.PERIODE_BAYAR_BUNGA, A.SISTEM_BAYAR_BUNGA, A.SISTEM_SETOR_AWAL, A.BIAYA_MATERAI, 
							A.BIAYA_TRANSFER, TO_CHAR(A.TGL_SETOR,'DD/MM/YYYY') TGL_SETOR, TO_CHAR(A.TGL_CLOSE,'DD/MM/YYYY') TGL_CLOSE, 
							A.KD_BANK, A.NAMA_CABANG, A.NO_REKENING, A.PEMILIK_REKENING, 
							A.ST_APPROVE, TO_CHAR(A.TGL_APPROVE,'DD/MM/YYYY') TGL_APPROVE, A.APPROVE_USER, 
							A.ST_TRANSFER, TO_CHAR(A.TGL_TRANSFER,'DD/MM/YYYY') TGL_TRANSFER, A.BUKTI_TRANSFER, 
							C.FULL_NAME, D.NAMA_JENIS_ANGGOTA, E.NAMA_BANK
					FROM	SIS_SIJAKA_MASTER A
							LEFT JOIN SIS_ANGGOTA B ON A.ID_ANGGOTA = B.ID_ANGGOTA
							LEFT JOIN SW_PERSON C ON B.PERSON_ID = C.PERSON_ID
							LEFT JOIN SIS_SETUP_JENIS_ANGGOTA D ON B.KD_JENIS_ANGGOTA = D.KD_JENIS_ANGGOTA
							LEFT JOIN KEU_BANK E ON E.KD_BANK = A.KD_BANK
					WHERE	(UPPER(NVL(A.ID_SIJAKA,'')) LIKE '%".strtoupper(post('keyword'))."%' 
							OR UPPER(NVL(A.ID_ANGGOTA,'')) LIKE '%".strtoupper(post('keyword'))."%' 
							OR UPPER(NVL(C.FULL_NAME,'')) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(C.IDENTITY_NUMBER,'')) LIKE '%".strtoupper(post('keyword'))."%') 
							AND NVL(A.ST_APPROVE,'0') = 1 AND NVL(A.ST_TRANSFER,'0') = '0' 
					ORDER BY ".(post('sort')=='' ? "NVL(A.ST_APPROVE,'0') ASC, A.TGL_PERMOHONAN" : post('sort'))." ".(post('order')=='' ? 'desc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function Add($arr_data){
		$this->db->insert('KEU_TRANS_KAS_BANK', $arr_data);
	}
	
	function GetSingleView($as_sijaka)
	{
		$result = $this->db->query("SELECT TA.ID_SIJAKA, TA.ID_ANGGOTA, AG.PERSON_ID,
						   TO_CHAR (TA.TGL_PERMOHONAN, 'DD/MM/YYYY') tgl_tagihan,
						   P.FULL_NAME NAMA_ANGGOTA,
						   TA.JML_DANA NOMINAL,
						   TA.BIAYA_MATERAI,
						   TA.JML_DANA+NVL(TA.BIAYA_MATERAI,0) TOTAL
					  FROM SIS_SIJAKA_MASTER TA INNER JOIN SIS_ANGGOTA AG
						   ON AG.ID_ANGGOTA = TA.ID_ANGGOTA
						   INNER JOIN SW_PERSON P ON AG.PERSON_ID = P.PERSON_ID
					 WHERE NVL (TA.ST_TRANSFER, '0') = '0' AND
							TA.ID_SIJAKA = '".$as_sijaka."' 
							");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	
}
?>